<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!-- mvvm: m:model  v:view vm:双向数据绑定 -->
    <input type="text" id="ipt">
    <script>
        let person = {};

        let val = '';

        let ipt = document.querySelector('#ipt');

        console.log(ipt)

        //person name属性变成访问器属性
        Object.defineProperty(person,'name',{
            set(newVal){
                console.log('设置值');
                val = newVal;
                ipt.value = newVal;
            },
            get(){
                console.log("获取值")
                return val
            }
        })

        //input事件

        ipt.addEventListener('input',(e) => {
            val = e.target.value
        })

    </script>
</body>
</html>